package com.woniuxy.carlife.carlifenewcomplaintsweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniuxy.carlife.carlifecommonsweb.util.CopyUtil;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.dto.UserComplaintDto;
import com.woniuxy.carlife.carlifenewcomplaintsdomain.param.UserComplaintParam;
import com.woniuxy.carlife.carlifenewcomplaintsweb.domain.UserComplaint;
import com.woniuxy.carlife.carlifenewcomplaintsweb.mapper.UserComplaintMapper;
import com.woniuxy.carlife.carlifenewcomplaintsweb.service.UserComplaintService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yp
 * @ClassName:UserComplaintServiceImpl
 * @Description:用户投诉服务
 * @date 2021/4/7 2:32
 **/
@Service
public class UserComplaintServiceImpl extends ServiceImpl<UserComplaintMapper, UserComplaint> implements UserComplaintService {
    @Resource
    private UserComplaintMapper userComplaintMapper;

    /*
     * 功能描述〈添加投诉〉
     * @author:yp
     * @param:UserComplaintParam
     * @return:
     * @Date 2021/4/12 15:16
     * @throws
     */
    @Override
    public int addUserComplaint(UserComplaintParam userComplaintParam) {
        UserComplaint userComplaint = CopyUtil.getOne(userComplaintParam,UserComplaint.class);
        int num = userComplaintMapper.insert(userComplaint);
        return num;
    }

    /*
     * 功能描述〈查询自己的投诉〉
     * @author:yp
     * @param:UserComplaintParam
     * @return:List<UserComplaintDto>
     * @Date 2021/4/12 15:17
     * @throws
     */
    @Override
    public List<UserComplaintDto> findUserComplaint(UserComplaintParam userComplaintParam) {
        QueryWrapper<UserComplaint> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userComplaintParam.getUserId());
        wrapper.eq("user_complaint_state",1);
        wrapper.or();
        wrapper.eq("user_complaint_state",2);
        List<UserComplaint> list = userComplaintMapper.selectList(wrapper);
        List<UserComplaintDto> list1 = CopyUtil.getList(list,UserComplaintDto.class);
        return list1;
    }
    /*
     * 功能描述〈门店查询投诉〉
     * @author:yp
     * @param:UserComplaintParam
     * @return:List<UserComplaintDto>
     * @Date 2021/4/12 15:17
     * @throws
     */
    @Override
    public List<UserComplaintDto> findComplaint(Integer storeId ) {
        QueryWrapper<UserComplaint> wrapper = new QueryWrapper<>();
        wrapper.eq("store_id",storeId);
        wrapper.eq("user_complaint_state",1);
        wrapper.or();
        wrapper.eq("user_complaint_state",2);
        List<UserComplaint> list = userComplaintMapper.selectList(wrapper);
        List<UserComplaintDto> list1 = CopyUtil.getList(list,UserComplaintDto.class);
        return list1;
    }

    /*
     * 功能描述〈修改投诉〉
     * @author:yp
     * @param: UserComplaintParam
     * @return:
     * @Date 2021/4/12 15:19
     * @throws
     */
    @Override
    public int updateUserComplaint(UserComplaintParam userComplaintParam) {
    UserComplaint userComplaint = CopyUtil.getOne(userComplaintParam,UserComplaint.class);
        UpdateWrapper<UserComplaint> wrapper=new UpdateWrapper<>();
        wrapper.eq("user_complaint_id",userComplaintParam.getUserComplaintId());
        int num = userComplaintMapper.update(userComplaint,wrapper);
        return num;
    }

    /*
     * 功能描述〈删除投诉〉
     * @author:yp
     * @param: UserComplaintParam
     * @return:
     * @Date 2021/4/12 15:21
     * @throws
     */
    @Override
    public int deleteUserComplaint(Integer userComplaintId) {
        UserComplaint userComplaint=new UserComplaint();
        userComplaint.setUserComplaintState(3);
        UpdateWrapper<UserComplaint> wrapper=new UpdateWrapper<>();
        wrapper.eq("user_complaint_id",userComplaintId);
        int num = userComplaintMapper.update(userComplaint,wrapper);
        return num;
    }
}
